package com.shuai.controller.feign;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shuai.model.entity.InterfaceInfo;
import com.shuai.common.ErrorCode;
import com.shuai.exception.BusinessException;
import com.shuai.mapper.InterfaceInfoMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName InnerInterfaceInfoServiceImpl
 * @Description TODO
 * @Author OTTO
 * @Date 2023/1/10 20:01
 */
@RestController
@RequestMapping("/feign")
public class InnerInterfaceInfoController {

    @Resource
    private InterfaceInfoMapper interfaceInfoMapper;

    /**
     * 查询接口是否存在
     * @param url
     * @param method
     * @return
     */
    @GetMapping("/getInterfaceInfo")
    public InterfaceInfo getInterfaceInfo(@RequestParam("url") String url,@RequestParam("method") String method) {
        if(StringUtils.isAnyBlank(url,method)){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        LambdaQueryWrapper<InterfaceInfo> lqw = new LambdaQueryWrapper<>();
        lqw.eq(InterfaceInfo::getUri,url)
                .eq(InterfaceInfo::getMethod,method);
        return interfaceInfoMapper.selectOne(lqw);
    }
}
